package com.uhomecp.lambda.base64_8;

import java.io.UnsupportedEncodingException;
import java.time.*;
import java.util.Base64;
import java.util.UUID;

public class Java8Tester {
    public static void main(String[] args) {
        try {
            String base64encodedString = Base64.getEncoder().encodeToString("ru?java8".getBytes("utf-8"));
            System.out.println("Base64 编码字符串 (基本) :" + base64encodedString);
            byte[] decode1 = Base64.getDecoder().decode(base64encodedString);
            System.out.println("原始字符串:"+new String(decode1, "utf-8"));

            String s = Base64.getUrlEncoder().encodeToString("ru?java".getBytes("utf-8"));
            System.out.println("Base64 编码字符串（URL）:"+s);
            byte[] decode2 = Base64.getUrlDecoder().decode(s);
            System.out.println("原始字符串（URL）:"+new String(decode2, "utf-8"));

            
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 10; i++) {
                sb.append(UUID.randomUUID().toString());
            }

            String s1 = Base64.getMimeEncoder().encodeToString(sb.toString().getBytes("utf-8"));
            System.out.println("Base64 编码字符串（MIME）:"+s1);
            byte[] decode = Base64.getMimeDecoder().decode(s1);
            System.out.println("原字符串（MIME）:"+new String(decode, "utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
